package models

import "sport_booking/dao"

type Access struct {
	Date string `json:"date"`
	Page string `json:"page"`
	IP   string `json:"ip"`
	UUID string `json:"uuid"`
}

/*
添加访问记录
*/
func AddAccessInfo(access *Access) (int64, error) {
	sqlStr := "INSERT INTO bk_access (access_date,access_page,access_ip,user_uuid) VALUES (?,?,?,?)"
	result, err := dao.DB.Exec(sqlStr, access.Date, access.Page, access.IP, access.UUID)
	if err != nil {
		return 0, err
	}
	return result.RowsAffected()
}

/*
根据uuid查询访问记录列表，一次10行
*/
func GetAccessInfoByUUID(uuid string, page int) ([]*Access, error) {
	var access []*Access
	sqlStr := "SELECT access_date,access_page,access_ip FROM bk_emails WHERE user_uuid=? LIMIT ?,10"
	err := dao.DB.Select(access, sqlStr, uuid, page*10)
	if err != nil {
		return nil, err
	}
	return access, nil
}
